package com.example.demo.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class RabbitmqConfig {
    @Bean
    public Queue queue() {
        return new Queue("queue1");
    }
    @Bean
    public Queue topicA() {
        return new Queue("topic.a");
    }

    @Bean
    public Queue topicB() {
        return new Queue("topic.b");
    }
    @Bean
    public Queue queueA() {
        return new Queue("fanout.a");
    }

    @Bean
    public Queue queueB() {
        return new Queue("fanout.b");
    }
    @Bean
    TopicExchange topicExchange() {
        return new TopicExchange("topicExchange");
    }

    @Bean
    FanoutExchange fanoutExchange() {
        return new FanoutExchange("fanoutExchange");
    }

    @Bean
    Binding bindingQueueA(Queue queueA, FanoutExchange fanoutExchange) {
        return BindingBuilder.bind(queueA).to(fanoutExchange);
    }
    @Bean
    Binding bindingQueueB(Queue queueB, FanoutExchange fanoutExchange) {
        return BindingBuilder.bind(queueB).to(fanoutExchange);
    }
    @Bean
    Binding bindingA() {
        return BindingBuilder.bind(topicA()).to(topicExchange()).with("color.red");
    }

    @Bean
    Binding bindingMessages() {
        return BindingBuilder.bind(topicB()).to(topicExchange()).with("color.#");
    }

    @Bean
    public Queue delay_queue_2() {
        return new Queue("delay_queue_2");
    }
    @Bean
    CustomExchange delayExchange() {
        Map<String, Object> args = new HashMap<>();
        args.put("x-delayed-type", "direct");
        return new CustomExchange("delayed_exchange2","x-delayed-message",true, false, args);
    }
    @Bean
    Binding bindingDelay() {
        return BindingBuilder.bind(delay_queue_2()).to(delayExchange()).with("delay_queue_2").noargs();
    }
}
